<?php
class cls_control_supplier extends cls_control_base
{
	function supplier_list_show()
	{
		$permission_serve = parent::get_serve('permission');
		$permission_serve->check_permission('SUPPLIER_MANAGE');
		$supplier_list = parent::serve_action('get_supplier_list');
		$this->smarty->assign('supplier_list', $supplier_list);
		$this->smarty->display('supplier/supplier_list.htm');
	}
	
	function create_supplier_show()
	{
		$permission_serve = parent::get_serve('permission');
		$permission_serve->check_permission('SUPPLIER_MANAGE');
		$this->smarty->display('supplier/create_supplier_show.htm');
	}
	
	function create()
	{
		$permission_serve = parent::get_serve('permission');
		$permission_serve->check_permission('SUPPLIER_MANAGE');
		$parameter = array(
				'sp_name' => $_POST['sp_name'],
				'sp_linkman' => trim($_POST['sp_linkman']),
				'sp_tel' => trim($_POST['sp_tel']),
				'sp_addr' => trim($_POST['sp_addr']),
				'sp_note' => trim($_POST['sp_note']),
		);
	
		$supplier_serve = parent::get_serve();
		$result = $supplier_serve->create($parameter);
		if (!$result['success']) {
			echo $result['msg'];
		} else {
			echo "创建成功";
		}
	}
	
	function export_supplier()
	{
		$permission_serve = parent::get_serve('permission');
		$permission_serve->check_permission('SUPPLIER_MANAGE');
		$excel = new PHPExcel();
		$supplier_list = parent::serve_action('get_supplier_list');
		$excel->setActiveSheetIndex(0);
		$objActSheet = $excel->getActiveSheet();
		$objActSheet->setTitle('供货商列表');
		$objActSheet->setCellValueExplicit('A1', '供货商ID', PHPExcel_Cell_DataType::TYPE_STRING);
		$objActSheet->setCellValueExplicit('B1', '供货商', PHPExcel_Cell_DataType::TYPE_STRING);
		$objActSheet->setCellValueExplicit('C1', '联系人', PHPExcel_Cell_DataType::TYPE_STRING);
		$objActSheet->setCellValueExplicit('D1', '联系电话', PHPExcel_Cell_DataType::TYPE_STRING);
		$objActSheet->setCellValueExplicit('E1', '地址', PHPExcel_Cell_DataType::TYPE_STRING);
		$objActSheet->setCellValueExplicit('F1', '备注', PHPExcel_Cell_DataType::TYPE_STRING);
		$row = 1;
		foreach ($supplier_list as $supplier)
		{
			$row++;
			$col = 65;
			foreach ($supplier as $item)
			{
				$c = chr($col);
				$objActSheet->setCellValueExplicit("{$c}{$row}", $item, PHPExcel_Cell_DataType::TYPE_STRING);
				$col++;
			}
		}
		export_excel('供货商列表', $excel);
	}
}